package org.example.timetask;


import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class BandImportTimeTask {
    @Autowired
    private JobLauncher jobLauncher;
    @Autowired
    private Job importBandJob;

//    @Scheduled(fixedRate = 60 * 1000)
    public void importEveryMinute() {
        try {
            log.info("Time task scheduled by Spring.");
            JobParameters jobParameters = new JobParametersBuilder().addLong(
                    "time", System.currentTimeMillis()).toJobParameters();
            jobLauncher.run(importBandJob, jobParameters);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
